<!--
Date: 2025-08-13
Copyright (c) 2025 Industrial Software Feature Database
-->
<template>
  <div class="model">
    <ModelList v-if="showModelList" :modelId="modelId" :nodeId="nodeId" :cardScrollTop="cardScrollTop" @handleEvent="handleEvent" />
    <NewElementModel
      v-if="addVisible"
      :modelId="modelId"
      :nodeId="nodeId"
      :cardScrollTop="cardScrollTop"
      :modelListType="modelListType"
      :rowData="rowData"
      @handleEvent="handleEvent"
    />
  </div>
</template>
<script setup>
import ModelList from './component/ModelList.vue';
import NewElementModel from './component/NewElementModel.vue';
const showModelList = ref(true);
const addVisible = ref(false);
const modelListType = ref('');
const rowData = ref(null);
const modelId = ref('');
const nodeId = ref('');
const cardScrollTop = ref(0);
const handleEvent = (data) => {
  if (data.component === 'add') {
    cardScrollTop.value = data.cardScrollTop;
    modelId.value = data.modelId;
    nodeId.value = data.nodeId;
    rowData.value = data.row ? data.row : null;
    showModelList.value = false;
    addVisible.value = true;
    modelListType.value = 'add';
  }
  if (data.component === 'view') {
    cardScrollTop.value = data.cardScrollTop;
    modelId.value = data.modelId;
    nodeId.value = data.nodeId;
    rowData.value = data.row;
    showModelList.value = false;
    addVisible.value = true;
    modelListType.value = 'view';
  }
  if (data.component === 'modify') {
    cardScrollTop.value = data.cardScrollTop;
    modelId.value = data.modelId;
    nodeId.value = data.nodeId;
    rowData.value = data.row;
    showModelList.value = false;
    addVisible.value = true;
    modelListType.value = 'modify';
  }
  if (data.component === 'modelList') {
    cardScrollTop.value = data.cardScrollTop;
    modelId.value = data.modelId;
    nodeId.value = data.nodeId;
    rowData.value = null;
    showModelList.value = true;
    addVisible.value = false;
  }
};
</script>
<style lang="scss" scoped>
.model {
  height: calc(100vh - 84px);
  width: 100%;
}
</style>
